import { createStore } from 'vuex';
import { getItem, setItem } from '../utils/storage';

export default createStore({
  state: {
    author: getItem('author') || '@煜ccc',
    description: getItem('description') || 'https://gitee.com/chen-1999',
    userInfo: getItem('userInfo') || {},
    closeLoadingUI: getItem('closeLoadingUI') || false,
    activePage: getItem('activePage') || 'home',
  },
  mutations: {
    setAuthor (state, val) {
      state.author = val;
      setItem('author', val);
    },
    setDescription (state, val) {
      state.description = val;
      setItem('description', val);
    },
    setUserInfo (state, val) {
      state.userInfo = val;
      setItem('userInfo', val);
    },
    setCloseLoadingUI (state, val) {
      state.closeLoadingUI = val;
      setItem('closeLoadingUI', val);
    },
    setActivePage (state, val) {
      state.activePage = val;
      setItem('activePage', val);
    },
  },
  actions: {},
  modules: {}
});
